package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.dto.company.CompanyInfoBindDto;
import com.ruoyi.workflow.constants.ApplyStatusConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CompanyInfoMapper;
import com.ruoyi.system.domain.CompanyInfo;
import com.ruoyi.system.service.ICompanyInfoService;

/**
 * 单位基本信息Service业务层处理
 *
 * @author 周志雄
 * @date 2024-03-09
 */
@Service
public class CompanyInfoServiceImpl implements ICompanyInfoService
{
    @Autowired
    private CompanyInfoMapper companyInfoMapper;

    /**
     * 查询单位基本信息
     *
     * @param companyId 单位基本信息主键
     * @return 单位基本信息
     */
    @Override
    public CompanyInfo selectCompanyInfoById(Long companyId)
    {
        return companyInfoMapper.selectCompanyInfoById(companyId);
    }

    /**
     * 查询单位基本信息列表
     *
     * @param companyInfo 单位基本信息
     * @return 单位基本信息
     */
    @Override
    public List<CompanyInfo> selectCompanyInfoList(CompanyInfo companyInfo)
    {
        return companyInfoMapper.selectCompanyInfoList(companyInfo);
    }

    /**
     * 新增单位基本信息
     *
     * @param companyInfo 单位基本信息
     * @return 结果
     */
    @Override
    public int insertCompanyInfo(CompanyInfo companyInfo)
    {
        return companyInfoMapper.insertCompanyInfo(companyInfo);
    }

    /**
     * 修改单位基本信息
     *
     * @param companyInfo 单位基本信息
     * @return 结果
     */
    @Override
    public int updateCompanyInfo(CompanyInfo companyInfo)
    {
        return companyInfoMapper.updateCompanyInfo(companyInfo);
    }

    /**
     * 批量删除单位基本信息
     *
     * @param companyIds 需要删除的单位基本信息主键
     * @return 结果
     */
    @Override
    public int deleteCompanyInfoByIds(Long[] companyIds)
    {
        return companyInfoMapper.deleteCompanyInfoByIds(companyIds);
    }

    /**
     * 删除单位基本信息信息
     *
     * @param companyId 单位基本信息主键
     * @return 结果
     */
    @Override
    public int deleteCompanyInfoById(Long companyId)
    {
        return companyInfoMapper.deleteCompanyInfoById(companyId);
    }

    /**
     * 解绑单位
     * @param companyInfo
     */
    @Override
    public void updateCompanyInfoUnBind(CompanyInfo companyInfo) {
        companyInfoMapper.updateCompanyInfoUnBind(companyInfo);
    }

    /**
     * 根据单位全称搜索单位基本信息
     * @param companyName
     * @return
     */
    @Override
    public CompanyInfoBindDto selectCompanyInfoByName(String companyName) {
        CompanyInfoBindDto companyInfoBindDto = companyInfoMapper.selectCompanyInfoByName(companyName);
        if(companyInfoBindDto!=null) {
            String applyStatus = companyInfoBindDto.getApplyStatus();
            companyInfoBindDto.setApplyStatus(ApplyStatusConstant.getApplyStatus(Integer.valueOf(applyStatus)));
        }
        return companyInfoBindDto;
    }

    /**
     * 根据用户ID查询单位信息
     * @param userId
     * @return
     */
    @Override
    public CompanyInfo selectCompanyInfoByUserId(String userId) {
        return companyInfoMapper.selectCompanyInfoByUserId(userId);
    }
}
